package light.head.dao.oa;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import light.head.constant.Parm;
import light.head.enm.RESULT;
import light.head.framework.base.BaseDAO;
import light.head.framework.entity.PageBean;
import light.head.model.Album;

@Service
public class AlbumDAO extends BaseDAO<Album, Integer>{

	public RESULT findByMap(List<Integer> ocs, Map<String, String> map, PageBean pb){
		if( null == ocs || ocs.size() == 0) return null;
		StringBuffer hql = new StringBuffer("FROM Album al WHERE al.deleted = 0 AND al.oc IN (");

		List<Object> list = new ArrayList<Object>();
		for (Integer i : ocs) {
			hql.append("?,");
			list.add(i);
		}
		hql.deleteCharAt(hql.length() - 1).append(")");
		if (null != map) {
			String oc = map.get(Parm.OC);
			if(isNotNull(oc)) {
				hql.append(" AND al.oc = ?");
				list.add(Integer.parseInt(oc));
			}
		}
		hql.append(" ORDER BY al.code DESC");
		
		if (findToPageBean(hql.toString(), pb, list) == RESULT.SUCCESS)
			return RESULT.SUCCESS;
		
		return RESULT.ERROR;
	}
}
